#include "GameMap.h"
#include "General Structures.hpp"
#include "Globals.hpp"
#include "Defines.hpp"


// ================= ~ctors ===============
GameMap::GameMap(string mapfile):m_Grid(mapfile),
								m_Partition(m_Grid.Width()* TILE_DIMENSIONS, m_Grid.Height() * TILE_DIMENSIONS, 
											m_Grid.Width() / 10, m_Grid.Height() / 10, 500)
{
	m_pNavGraph = SparseGraph<NavGraphNode<void*>, GraphEdge>::GetGraph(m_Grid);
	m_Minimap.Load(mapfile.c_str());
	m_Minimap.SetLocation(10, DataLoader->WINDOW_HEIGHT - m_Minimap.GetDimensions().h - 10);
}

GameMap::~GameMap()
{
	NullDelete(m_pNavGraph); 
	m_Minimap.Delete();
}


// ===========================AddEntity=====================
// Adds an entity to the cellspace partition and the minimap

void GameMap::AddEntity(BaseGameEntity* anEntity)
{
	m_Partition.AddEntity(anEntity);
	Vector2D pos(anEntity->GetX(), anEntity->GetY());
	m_Minimap.AddEntity(anEntity->ID(), pos, red);
}

// ======================= UpdateMinimapEntity ========================
// Updates the specified entity on the minimap.  This readjusts the pixel location
// of that entity on the minimap
void GameMap::UpdateMinimapEntity(int ID, const Vector2D& position)
{
	m_Minimap.UpdateEntity(ID, position);
}

void GameMap::RenderGrid()
{
	m_Grid.Render();
	
}

void GameMap::RenderMinimap()
{
	m_Minimap.RenderMinimap();
	m_Minimap.RenderScreen();
	m_Minimap.RenderEntities();
}

